var app = getApp();
var config = require('../../../config.js');
Page({
  data: {
    ProductList:[],
    page: 1,
    pageSize: 20,
    hasMoreData: true,
    imgPath: config.imgPath
  },
  onShow: function () {
    this.setData({
      page:1
    })
    this.loadData()
  },
  onShareAppMessage:function(){

  },
  loadData(){
    let self = this
    app.request({
      url: 'api/wechat/GetPageOfProductByWechat',
      method: "POST",
      data: {
        sortType:0,
        page: self.data.page,
        pageSize: self.data.pageSize
      },
      success: function (res) {
        console.log(res)
        if (res.data != null && res.data.Data.length > 0) {
          var listTemp = self.data.ProductList

          if (self.data.page == 1) {
            listTemp = []
          }
          var list = res.data.Data
          if (list.length < self.data.pageSize) {
            self.setData({
              ProductList: listTemp.concat(list),
              hasMoreData: false
            })
          } else {
            self.setData({
              ProductList: listTemp.concat(list),
              hasMoreData: true,
              page: self.data.page + 1
            })
          }
        }
      }
    })
  },
  //下拉
  onPullDownRefresh: function () {
    this.setData({
      page: 1
    })
    this.loadData()
    wx.stopPullDownRefresh();
  },
  //上拉
  onReachBottom: function () {
    if (this.data.hasMoreData) {
      this.loadData()
    } else {
      wx.showToast({
        title: '没有更多了',
        icon: 'none',
      })
    }
  },
})